package mop.model.task.state;

import mop.exception.BusinessRule2Exception;
import mop.exception.BusinessRule3Exception;
import mop.exception.RecursiveBusinessRule2Exception;
import mop.model.task.Task;
import mop.model.task.TaskInterface;

/**
 * State class for an available task
 * 
 * @author 	MOP Team 7
 */
public class Available extends Unfinished 
{

	/**
	 * Constructor
	 * @param t	Task for this state
	 * @post	Task is set to given task
	 * 	|super(t)
	 * 
	 * @throws BusinessRule2Exception
	 *     | @see rule2isMet
	 * 
	 * @throws BusinessRule3Exception
	 * 	   | @see rule3isMet
	 * 
	 * @throws RecursiveBusinessRule2Exception 
	 * 	   | @see Unfinished()
	 */
	public Available(Task t) throws BusinessRule2Exception, BusinessRule3Exception
	{
		super(t);
		
		TaskInterface problem = rule2isMet();
		
		if(problem != null)
		{
			throw new BusinessRule2Exception(problem);
		}
		
		if(rule3isMet() == false)
		{
			throw new BusinessRule3Exception(this.getTask());
		}
	}
	
	/**
	 * Constructor without exceptions !! Construction is Forced
	 * @param t Task for this state
	 * @param ignore boolean that tells us wether it's a forced construction
	 */
	public Available(Task t,boolean ignore)
	{
		super(t,ignore);
	}
	
	/**
	 * Copy Constructor
	 * @param oldstate
	 * 
	 * @throws BusinessRule2Exception
	 *     | @see rule2isMet
	 * 
	 * @throws BusinessRule3Exception
	 * 	   | @see rule3isMet
	 * 
	 * @throws RecursiveBusinessRule2Exception 
	 * 	   | @see Unfinished()
	 */
	public Available(State oldstate) throws BusinessRule2Exception, BusinessRule3Exception, RecursiveBusinessRule2Exception 
	{ 
		super(oldstate);
		
		TaskInterface problem = rule2isMet();
		if(problem != null)
		{
			throw new BusinessRule2Exception(problem);
		}
		
		if(rule3isMet() == false)
		{
			throw new BusinessRule3Exception(this.getTask());
		}
	}
	
	/***************************************************************************
	 * 						Java object interface
	 ***************************************************************************/

	/**
	 * Compare state with string for ease of use
	 * 
	 * @param state
	 * 		the state name to compare with
	 * 
	 * @return this.getName.equals(state)
	 */
	public boolean equals(String state)
	{
		return (this.getName().equals(state)) || state.equals(Unfinished.stateName());
	}
	/**
	 * @see 	Object#toString()
	 */
	public String toString()
	{
		return "Available";
	}
	/**
	 * return a string of the class name
	 * @return "Available"
	 */
	public static String stateName()
	{
		return "Available";
	}
	
}
